%% Character Generation Script
% By: John M. Murray
tic
%%
% This script will generate a basic NPC of the given point value with
% random atributes. Note that NPCs dont take as many adds/dis so point
% values should be much lower then the PCs!

points=50;
offset=0;
maxoffset=points/2;

%% Script Stuff
%
points_i=points;

%%
% Setup the basic stats
NPC.ST=10;
NPC.DX=10;
NPC.IQ=10;
NPC.HT=10;
NPC.HP=NPC.ST;
NPC.WILL=NPC.IQ;
NPC.PER=NPC.IQ;
NPC.FP=NPC.HT;

%%
% Spend points on stats

while(points>1)
	switch randi(16)
		case 1,
			% Try to buy ST
			if(points>=10)
				NPC.ST=NPC.ST+1;
				NPC.HP=NPC.HP+1;
				points = points - 10;
			end
		case 2,
			% Try to buy DX
			if(points>=20)
				NPC.DX=NPC.DX+1;
				points = points - 20;
			end
		case 3,
			% Try to buy IQ
			if(points>=20)
				NPC.IQ=NPC.IQ+1;
				NPC.WILL=NPC.WILL+1;
				NPC.PER=NPC.PER+1;
				points = points - 20;
			end
		case 4,
			% Try to buy HT
			if(points>=20)
				NPC.HT=NPC.HT+1;
				NPC.FP=NPC.FP+1;
				points = points - 20;
			end
		case 5,
			% Try to buy HP
			if(points>=2)
				NPC.HP=NPC.HP+1;
				points = points - 2;
			end
		case 6,
			% Try to buy WILL
			if(points>=5)
				NPC.WILL=NPC.WILL+1;
				points = points - 5;
			end
		case 7,
			% Try to buy PER
			if(points>=5)
				NPC.PER=NPC.PER+1;
				points = points - 5;
			end
		case 8,
			% Try to buy FP
			if(points>=3)
				NPC.FP=NPC.FP+1;
				points = points - 3;
			end
		case 9,
			% Try to sell ST
			if((offset+10)<maxoffset && NPC.ST>3)
				NPC.ST=NPC.ST-1;
				NPC.HP=NPC.HP-1;
				points = points + 10;
				offset = offset + 10;
			end
		case 10,
			% Try to sell DX
			if((offset+20)<maxoffset && NPC.DX>3)
				NPC.DX=NPC.DX-1;
				points = points + 20;
				offset = offset + 20;
			end
		case 11,
			% Try to sell IQ
			if((offset+20)<maxoffset && NPC.IQ>6)
				NPC.IQ=NPC.IQ-1;
				NPC.WILL=NPC.WILL-1;
				NPC.PER=NPC.PER-1;
				points = points + 20;
				offset = offset + 20;
			end
		case 12,
			% Try to sell HT
			if((offset+20)<maxoffset && NPC.HT>6)
				NPC.HT=NPC.HT-1;
				NPC.FP=NPC.FP-1;
				points = points + 20;
				offset = offset + 20;
			end
		case 13,
			% Try to sell HP
			if((offset+2)<maxoffset && NPC.HP>6)
				NPC.HP=NPC.HP-1;
				points = points + 2;
				offset = offset + 2;
			end
		case 14,
			% Try to sell WILL
			if((offset+5)<maxoffset && NPC.WILL>6)
				NPC.WILL=NPC.WILL-1;
				points = points + 5;
				offset = offset + 5;
			end
		case 15,
			% Try to sell PER
			if((offset+5)<maxoffset && NPC.PER>6)
				NPC.PER=NPC.PER-1;
				points = points + 5;
				offset = offset + 5;
			end
		case 16,
			% Try to sell FP
			if((offset+3)<maxoffset && NPC.FP>6)
				NPC.FP=NPC.FP-1;
				points = points + 3;
				offset = offset + 3;
			end
		otherwise,
	end		
end
NPC %#ok<NOPTS>